<template>
  <a-card>
    <div>
      <a-space class="operator">
        <a-button @click="" type="primary">下发</a-button>
      </a-space>
      <standard-table
        :scroll="tableScroll"
        :columns="columns"
        :dataSource="dataSource"
        :selectedRows.sync="selectedRows"
        @clear="onClear"
        @change="onChange"
        @selectedRowChange="onSelectChange"
      >
      </standard-table>
    </div>
  </a-card>
</template>

<script>

import StandardTable from '@/components/table/StandardTable'
const columns = [
  {
    title: '模板指令名称',
    dataIndex: 'no'
  },
  {
    title: '操作对象',
    dataIndex: 'no'
  },
  {
    title: '动作',
    width:'100px',
    scopedSlots: { customRender: 'action' }
  }
]
const dataSource = []

for (let i = 0; i < 100; i++) {
  dataSource.push({
    key: i,
    no: 'NO ' + i,
    description: '这是一段描述',
    callNo: Math.floor(Math.random() * 1000),
    status: Math.floor(Math.random() * 10) % 4,
    updatedAt: '2018-07-26'
  })
}

export default {
  name: 'QueryList',
  components: {StandardTable},
  data () {
    return {
      isLineBody:false,
      advanced: false,
      columns: columns,
      dataSource: dataSource,
      lineDataSource:[],
      selectedRows: []
    }
  },
  authorize: {
    deleteRecord: 'delete'
  },
  computed:{
      getWidth: function () {
      if (this.defColumns.length > 10) {
        return { width: "500px" };
      }
    },
    tableScroll: function () {
      if (this.columns.length > 10) {
        return { x: 800, y: 450 };
      }
    },
  },
  methods: {
    deleteRecord(key) {
      this.dataSource = this.dataSource.filter(item => item.key !== key)
      this.selectedRows = this.selectedRows.filter(item => item.key !== key)
    },
    toggleAdvanced () {
      this.advanced = !this.advanced
    },
    remove () {
      this.dataSource = this.dataSource.filter(item => this.selectedRows.findIndex(row => row.key === item.key) === -1)
      this.selectedRows = []
    },
    onClear() {
      this.$message.info('您清空了勾选的所有行')
    },
    onStatusTitleClick() {
      this.$message.info('你点击了状态栏表头')
    },
    onChange() {
      this.$message.info('表格状态改变了')
    },
    onSelectChange() {
      this.$message.info('选中行改变了')
    },
    addNew () {
      this.dataSource.unshift({
        key: this.dataSource.length,
        no: 'NO ' + this.dataSource.length,
        description: '这是一段描述',
        callNo: Math.floor(Math.random() * 1000),
        status: Math.floor(Math.random() * 10) % 4,
        updatedAt: '2018-07-26'
      })
    },
    handleMenuClick (e) {
      if (e.key === 'delete') {
        this.remove()
      }
    }
  }
}
</script>

<style lang="less" scoped>
  .search{
    margin-bottom: 54px;
  }
  .fold{
    width: calc(100% - 216px);
    display: inline-block
  }
  .operator{
    margin-bottom: 18px;
  }
  .tabs-uhn{
    width: 70%;
    text-align: center;
    padding:12px 0px;
    box-shadow: 3px 3px 3px#E7EAED;
    border-radius: 9px;
    background-color: #F2F2F2;
  }
  @media screen and (max-width: 900px) {
    .fold {
      width: 100%;
    }
  }
</style>
